<?php
/**
 * <b>RUBIK IT Solution & Development ltd.</b>
 *
 * PROJECT		: Rubik Ultimate Framework
 * @version 	: 1.1
 * COPYRIGHT    : 2008
 * ------------------------------------------------------
 * 
 * Created on	:  Jul 14, 2008
 * 
 */

// no direct access
defined ( '_FW_EXEC' ) or die ( 'Restricted access' );
RCoreImporter::cls("html.AbstractHtmlCombobox" );

class HtmlCombobox extends AbstractHtmlCombobox {
	
	function __construct($cbxName) {
		$this->_cbxName = $cbxName;
	}
	
	function category_get_tree($emptyText = " - - Select Filter - - ", $parentid = 0, $space = '--', $trees = NULL) {
		if ($emptyText !== null) {
			$trees [0] = $emptyText;
		}
		
		if (! $trees)
			$trees = array ();
		if ($parentid != 0)
			$sql = mysql_query ( "SELECT * FROM category WHERE parent_id = " . intval ( $parentid ) );
		else
			$sql = mysql_query ( "SELECT * FROM category" ) or die ( 'nono' );
		
		while ( $rs = mysql_fetch_assoc ( $sql ) ) {
			if (! array_key_exists ( $rs ['cat_id'], $trees ))
				$trees [$rs ['cat_id']] = $space . " " . $rs ['cat_name'];
			$trees = HtmlCombobox::category_get_tree ( $emptyText, $rs ['cat_id'], $space . '--', $trees );
		
		}
		return $trees;
	}
	
	function createCombobox($emptyText = " - - Select Filter - - ", $space = " -- ", $cssCls = null, $style = null, $id = null, $extAttributes = "") {
		RCoreImporter::cls("helper.RHtmlHelper" );
		$fields = HtmlCombobox::category_get_tree ( $emptyText );
		return RHtmlHelper::createSelectHtml ( $this->_cbxName, $fields, $this->_selectedValue, $extAttributes, $id, $cssCls, $style );
	}
}

?>